package com.java.star.novel.core.bean;

import com.java.star.novel.core.enums.ResultCode;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Map;

@Data
@NoArgsConstructor
public class Result implements Serializable {
    private static final long serialVersionUID = 42L;

    private int code;
    private String msg;
    private Map<String, Object> data;

    private Result(ResultCode resultCode, Map data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public static Result ok() {
        return new Result(ResultCode.SUCCESS, null);
    }

    public static Result fail() {
        return new Result(ResultCode.FAIL, null);
    }

    public Result data(Map data) {
        setData(data);
        return this;
    }

    public Result code(ResultCode resultCode) {
        setCode(resultCode.getCode());
        setMsg(resultCode.getMsg());
        return this;
    }

}
